# for i in range(10):
#     print(i)

# def foo():
#     x = 0
#     for i in range(10):
#         print(i)
#     print(f'result:{x}')


# def foo(x, y):
#     result = None
#     try:
#         result = x +y
#     except Exception as e:
#         try:
#             result = int(x) + int(y)
#         except:
#             raise e
#     finally:
#         pass
#     return result
#
#
# print(foo(1, 'a'))

# try:
#     1/0
# except:
#     print("Catch Error")
# else:
#     print("Catch else")
# finally:
#     print("finally")


class IntChangeError(Exception):    # 继承自基类Exception
    def __init__(self, reason):
        self.reason = reason

    def __str__(self):
        return self.reason


def fib_for(n):
    try:
        n = int(n)
    except Exception as e:
        raise IntChangeError("类型转换错误,您输入的是不能装换为数字的的字符")
	else:
        if n == 0:
            return [0]
        elif n == 1 or n == 2:
            return [0, 1]

        a, b = 0, 1
        fib_list = [0, 1]
        for i in range(n - 1):
            a = a + b
            b, a = a, b
            fib_list.append(b)
        return fib_list


def fib_while(n):
    try:
        n = int(n)
    except Exception as e:
        raise IntChangeError("类型转换错误,您输入的是不能装换为数字的的字符")
    else:
        if n == 0:
            return [0]
        elif n == 1 or n == 2:
            return [0, 1]

        a, b = 0, 1
        fib_list = [0, 1]
        i = 0
        while i < n - 1:
            a = a + b
            b, a = a, b
            fib_list.append(b)
            i += 1
        return fib_list


if __name__ == '__main__':
    print(fib_for(10))
    print(fib_for('10a'))
    print(fib_while(10))
    print(fib_while('10a'))
    




